import './Optionlist.scss'
import React, { Component } from 'react';
import { index_goodlist } from '../utils/api'
class Optionlist extends Component {
    constructor(props) {
        super(props)
        this.state = { arrlist: [] }
    }
    componentDidMount() {
        index_goodlist({ count: 4 }).then((res) => {
            console.log(res.data)
            this.setState({ arrlist: res.data.list })
        })
    }
    render() {
        return (
            <div>
                <div className="arrlist">
                    {
                        this.state.arrlist && this.state.arrlist.map((element, index) => {
                            return (
                                <div className="arrlist" key={index} onClick={() => { this.props.history.push({ pathname: '/detail', state: { goodid: element.id } }) }}>
                                    <img src={element.pic} alt="" />
                                    <div className="arrtext">{element.name}</div>
                                    <div className="arrprice">活动价￥{element.salesPrice.value}</div>
                                </div>
                            )
                        })
                    }
                </div>
            </div>
        );
    }
}

export default Optionlist;